﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using M.Dao.Client.Core;

namespace M.Dao.Client
{
    /// <summary>
    /// 数据库Schema
    /// </summary>
    public class SchemaRepository
    {

        public ISchemaAccess SchemaAccess { get; set; }

        public string DB { get; set; }

        public string AccessToken { get; set; }


        public SchemaRepository(string daoUrl, string db, string accessToken)
        {
            var schemaAccess = new SchemaAccess(daoUrl);

            this.DB = db;
            this.AccessToken = accessToken;

            this.SchemaAccess = schemaAccess;
        }

        public string[] Tables()
        {
            DataResult <TableInfo[]> result = this.SchemaAccess.Tables<TableInfo[]>(this.DB, this.AccessToken);

            string[] data = result.data.Select(q => q.TABLE_NAME).OrderBy(q=>q).ToArray();

            return data;
        }

    }



}
